home *** CD-ROM | disk | FTP | other *** search
/ OpenGL Superbible (2nd Edition) / OpenGL SuperBible e2.iso / tools / FLTK-1.0.6 / src / fl_labeltype.cxx < prev    next >
Encoding:
C/C++ Source or Header  |  1999-01-07  |  3.7 KB  |  122 lines

  1. //
  2. // "$Id: fl_labeltype.cxx,v 1.6 1999/01/07 19:17:40 mike Exp $"
  3. //
  4. // Label drawing routines for the Fast Light Tool Kit (FLTK).
  5. //
  6. // Copyright 1998-1999 by Bill Spitzak and others.
  7. //
  8. // This library is free software; you can redistribute it and/or
  9. // modify it under the terms of the GNU Library General Public
  10. // License as published by the Free Software Foundation; either
  11. // version 2 of the License, or (at your option) any later version.
  12. //
  13. // This library is distributed in the hope that it will be useful,
  14. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  16. // Library General Public License for more details.
  17. //
  18. // You should have received a copy of the GNU Library General Public
  19. // License along with this library; if not, write to the Free Software
  20. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
  21. // USA.
  22. //
  23. // Please report all bugs and problems to "fltk-bugs@easysw.com".
  24. //
  25.  
  26. // Drawing code for the (one) common label types.
  27. // Other label types (symbols) are in their own source files
  28. // to avoid linking if not used.
  29.  
  30. #include <FL/Fl.H>
  31. #include <FL/Fl_Widget.H>
  32. #include <FL/Fl_Group.H>
  33. #include <FL/fl_draw.H>
  34.  
  35. void
  36. fl_no_label(const Fl_Label*,int,int,int,int,Fl_Align) {}
  37.  
  38. void
  39. fl_normal_label(const Fl_Label* o, int X, int Y, int W, int H, Fl_Align align)
  40. {
  41.   fl_font(o->font, o->size);
  42.   fl_color((Fl_Color)o->color);
  43.   fl_draw(o->value, X, Y, W, H, align);
  44. }
  45.  
  46. void
  47. fl_normal_measure(const Fl_Label* o, int& W, int& H) {
  48.   fl_font(o->font, o->size);
  49.   fl_measure(o->value, W, H);
  50. }
  51.  
  52. #define MAX_LABELTYPE 16
  53.  
  54. static Fl_Label_Draw_F* table[MAX_LABELTYPE] = {
  55.   fl_normal_label,
  56.   fl_no_label,
  57.   fl_normal_label,    // _FL_SYMBOL_LABEL,
  58.   fl_normal_label,    // _FL_SHADOW_LABEL,
  59.   fl_normal_label,    // _FL_ENGRAVED_LABEL,
  60.   fl_normal_label,    // _FL_EMBOSSED_LABEL,
  61.   fl_no_label,        // _FL_BITMAP_LABEL,
  62.   fl_no_label,        // _FL_PIXMAP_LABEL,
  63.   fl_no_label,        // _FL_IMAGE_LABEL,
  64.   // FL_FREE_LABELTYPE+n:
  65.   fl_no_label, fl_no_label, fl_no_label,
  66.   fl_no_label, fl_no_label, fl_no_label, fl_no_label,
  67. };
  68.  
  69. static Fl_Label_Measure_F* measure[MAX_LABELTYPE];
  70.  
  71. void Fl::set_labeltype(Fl_Labeltype t,Fl_Label_Draw_F* f,Fl_Label_Measure_F*m) 
  72. {
  73.   table[t] = f; measure[t] = m;
  74. }
  75.  
  76. ////////////////////////////////////////////////////////////////
  77.  
  78. // draw label with arbitrary alignment in arbitrary box:
  79. void Fl_Label::draw(int X, int Y, int W, int H, Fl_Align align) const {
  80.   if (!value) return;
  81.   table[type](this, X, Y, W, H, align);
  82. }
  83.  
  84. void Fl_Label::measure(int& W, int& H) const {
  85.   if (!value) return;
  86.   Fl_Label_Measure_F* f = ::measure[type]; if (!f) f = fl_normal_measure;
  87.   f(this, W, H);
  88. }
  89.  
  90. // The normal call for a draw() method:
  91. void Fl_Widget::draw_label() const {
  92.   int X = x_+Fl::box_dx(box());
  93.   int W = w_-Fl::box_dw(box());
  94.   if (W > 11 && align()&(FL_ALIGN_LEFT|FL_ALIGN_RIGHT)) {X += 3; W -= 6;}
  95.   draw_label(X, y_+Fl::box_dy(box()), W, h_-Fl::box_dh(box()));
  96. }
  97.  
  98. // draw() can use this instead to change the bounding box:
  99. void Fl_Widget::draw_label(int X, int Y, int W, int H) const {
  100.   // quit if we are not drawing a label inside the widget:
  101.   if ((align()&15) && !(align() & FL_ALIGN_INSIDE)) return;
  102.   draw_label(X,Y,W,H,align());
  103. }
  104.  
  105. // Anybody can call this to force the label to draw anywhere:
  106. extern char fl_draw_shortcut;
  107. void Fl_Widget::draw_label(int X, int Y, int W, int H, Fl_Align a) const {
  108.   if (flags()&SHORTCUT_LABEL) fl_draw_shortcut = 1;
  109.   Fl_Label l1 = label_;
  110.   if (!active_r()) l1.color = inactive((Fl_Color)l1.color);
  111.   l1.draw(X,Y,W,H,a);
  112.   fl_draw_shortcut = 0;
  113. }
  114.  
  115. // include these vars here so they can be referenced without including
  116. // Fl_Input_ code:
  117. #include <FL/Fl_Input_.H>
  118.  
  119. //
  120. // End of "$Id: fl_labeltype.cxx,v 1.6 1999/01/07 19:17:40 mike Exp $".
  121. //
  122.